package cjh;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import service.AdminRead;

import dao.JDBC_SQL;

import model.AdminVO;

public class Admin_Setting  extends JPanel {

	private Admin_Select as;
	private static AdminVO pass = new AdminVO();
	
	public Admin_Setting() {
	
		setLayout( new BorderLayout( 0, 0) );
		adminTop();		//JScrollPane chart는 table을보기위해 사용
		JScrollPane chart = new JScrollPane();
		add( chart, BorderLayout.CENTER );
		
		
		
		
		final DefaultTableModel model = new DefaultTableModel(){
				@Override
				public boolean isCellEditable(int row, int column) {	// 셀을 조작하는것을 
		
					return false;	// 금지함
				}
			
		};
		
		
		
		String title[]= { "순 번", "ID", "이 름", "Password", "연락처", "생성일" };
		model.setColumnIdentifiers( title );		// 행에 제목
		
		
		
		
		for ( AdminVO a : as.selectMember() ){
			String tr =	a.getAdmin_tr();
			String id = a.getAdmin_id();
			String name = a.getAdmin_name();
			String pw = a.getAdmin_pw();
			String tel = a.getAdmin_tel();
			String date = a.getReg_date();
			
			model.addRow( new String[]{ tr, id, name, pw, tel, date });
			
		}
		  
		
		
		
		
		JTable adminTable = new JTable();
		adminTable.addMouseListener( new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				
				if ( e.getClickCount() == 2 ){
					JTable admintable = (JTable) e.getSource();
					int row = admintable.getSelectedRow();//선택행+
					pass.setAdmin_tr( (String) model.getValueAt(row, 0) ) ;
					pass.setAdmin_id( (String) model.getValueAt(row, 1) ) ;
					pass.setAdmin_name( (String) model.getValueAt(row, 2) ) ;
					pass.setAdmin_pw( (String) model.getValueAt(row, 3) ) ;
					pass.setAdmin_tel((String) model.getValueAt(row, 4) ) ;
					pass.setReg_date( (String) model.getValueAt(row, 5) ) ;
					// int col = table.getSelectedColumn();		// 선택열
					// String val = (String) table.getValueAt(row, col);
					// String msg = row + "/" + col + "/" + val + "\n" + "더브루 클릭크";
					// String msg = row + ""; // + "/" + col + "/" + val + "\n" + "더브루 클릭크";
				
					new Admin_Dial( pass );
					// 체크박스 트루펄스
					
				
				}
								
			//	super.mouseClicked(e);
			}
			
		});
		
		
		adminTable.setModel(model);
		
		
				
		chart.setViewportView(adminTable);
		
	}
	
	
	private void adminTop(){
		
		JPanel top = new JPanel();
		
		JTextField serch = new JTextField();
		serch.setColumns( 30 );
		top.add( serch );	
		
		JButton see = new JButton();
		see.setText( "검 색" );
		
		JButton create = new JButton();
		create.setText( "추 가 등 록" );
		create.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		
				AdminVO v = new AdminVO();
				new Admin_Apend_AdminId( );
				
				
			}

		});
		
		top.add( see );		
		top.add( create );
		add(  top, BorderLayout.NORTH );
		
		
	} // adminTop
	
}  // class
